﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Common.Utilities;
    using DotNetNuke.Entities.Modules;
    using DotNetNuke.Services.Exceptions;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Runtime.CompilerServices;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class MenuManager : BaseModule, IPortable
    {
        [AccessedThroughProperty("PlaceHolder1")]
        private PlaceHolder _PlaceHolder1;

        public MenuManager()
        {
            base.Load += new EventHandler(this.Page_Load);
        }

        public string ExportModule(int ModuleID)
        {
            string str = string.Empty;
            return str;
        }

        public void ImportModule(int ModuleID, string Content, string Version, int UserID)
        {
        }

        private void Page_Load(object sender, EventArgs e)
        {
            try
            {
                SettingsController controller = new SettingsController();
                string str = "";
                Upgrade upgrade = new Upgrade();
                string testVersion = SharedFunctions.GetStoreSetting(this.PortalId, "version", "None");
                if (testVersion == "")
                {
                    SharedFunctions.CreateDir(this.PortalSettings, "productimages");
                    SharedFunctions.CreateDir(this.PortalSettings, "productdocs");
                    try
                    {
                        ImgReSize size = new ImgReSize();
                        FileSystemUtils.SaveFile(this.PortalSettings.HomeDirectoryMapPath + "noimage.png", size.BmpToBytes_MemStream(SharedFunctions.EmbeddedImage("noimage.png"), 0x48L, 4));
                    }
                    catch (Exception exception1)
                    {
                        ProjectData.SetProjectError(exception1);
                        Exception exception = exception1;
                        ProjectData.ClearProjectError();
                    }
                    str = upgrade.DoUpgrade(this.PortalId, base.StoreInstallPath, this.UserId);
                }
                if (SharedFunctions.VersionCompare(testVersion, this.ModuleConfiguration.DesktopModule.Version) != 0)
                {
                    str = upgrade.DoUpgrade(this.PortalId, base.StoreInstallPath, this.UserId);
                }
                testVersion = SharedFunctions.GetStoreSetting(this.PortalId, "version", "None");
                if (SharedFunctions.VersionCompare(testVersion, this.ModuleConfiguration.DesktopModule.Version) != 0)
                {
                    str = "NB_Store Portal Version " + testVersion + " mismatch with NB_Store Module Version " + this.ModuleConfiguration.DesktopModule.Version;
                }
                if (str != "")
                {
                    this.PlaceHolder1.Controls.Add(new LiteralControl(HttpUtility.HtmlDecode("<br />" + str)));
                }
                SharedFunctions.DisplayMsgText(Conversions.ToString(this.PortalId), this.PlaceHolder1, "backoffice.text", "");
                this.Controls.Add(new AdminMenu());
                if (SharedFunctions.GetStoreSettingBoolean(this.PortalId, "orderedit.flag"))
                {
                    CurrentCart.DeleteCart(this.PortalId);
                }
            }
            catch (Exception exception3)
            {
                ProjectData.SetProjectError(exception3);
                Exception exc = exception3;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        protected virtual PlaceHolder PlaceHolder1
        {
            get
            {
                return this._PlaceHolder1;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._PlaceHolder1 = value;
            }
        }
    }
}

